﻿/*
 * Copyright 2009 BAKUDO Michał Rabiński	 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package bakudo.utils.scrollers.smartScroll.scrollable {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;

	/**
	 * @author Bakudo Michał Rabiński
	 */
	public class ScrollableItem extends Sprite {

		//reference to scrollable item's model
		public var itemModel : ScrollableItemVO;

		//means if there was any add to scene before
		public var firstAdd : Boolean = true;	

		//width of item
		public var itemWidth : Number = 200;

		//height of item
		public var itemHeight : Number = 200;

		//unique item index
		public var itemIndex : uint;

		//textfield for tests
		public var t : TextField = new TextField();

		public function ScrollableItem() {
			init();
			addEventListener(Event.ADDED_TO_STAGE, onATS, false, 0, true);
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// PROTECTED METHODS
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		protected function init() : void {
			itemHeight = height;
			itemWidth = width;
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// PUBLIC METHODS
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		/**
		 * method initiated on creation of item and when position x and y are both set
		 * in createItem method initiation of BakudoSmartScroll class method : populate();
		 */
		public function handleElementReady() : void {
		}

		/**
		 * method initiated on every add on scene
		 */
		public function handleElementOnStage() : void {
		}

		/**
		 * method initiated on first add on scene
		 */
		public function handleElementFirstTimeAdd() : void {
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// PUBLIC LISTENERS
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		private function onATS(e : Event) : void {
			if (firstAdd) {
				firstAdd = false;
				handleElementFirstTimeAdd();
			}
			handleElementOnStage();
		}
	}
}
